package com.ddwl.wallet.service;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.wallet.WithdrawChannelConfAddBo;
import com.ddwl.schema.bo.wallet.WithdrawChannelConfEnableBo;
import com.ddwl.schema.bo.wallet.WithdrawChannelConfUpdateBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.wallet.WithdrawChannelConfVo;
import com.ddwl.wallet.dao.WithdrawChannelConfDao;
import com.ddwl.wallet.dao.model.WithdrawChannelConf;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2021/6/23 17:36
 */
@Service
public class WithdrawChannelConfService {

    @Resource
    private WithdrawChannelConfDao withdrawChannelConfDao;


    public void add(WithdrawChannelConfAddBo bo) {
        WithdrawChannelConf conf = BeanConverUtils.convertBean(bo, WithdrawChannelConf.class);
        conf.setEnable(BaseEnum.StatusEnum.ENABLE.getCode());
        withdrawChannelConfDao.insert(conf);
    }

    public void update(WithdrawChannelConfUpdateBo bo) {
        WithdrawChannelConf conf = BeanConverUtils.convertBean(bo, WithdrawChannelConf.class);
        withdrawChannelConfDao.updateByPrimaryKeySelective(conf);
    }

    public void enable(WithdrawChannelConfEnableBo bo) {
        WithdrawChannelConf conf = BeanConverUtils.convertBean(bo, WithdrawChannelConf.class);
        withdrawChannelConfDao.updateByPrimaryKeySelective(conf);
    }

    public PageVo<WithdrawChannelConfVo> page(PageBo bo) {
        PageHelper.startPage(bo.getPage(), bo.getPageSize(), MySqlUtil.orderBy(bo.getSort(), bo.isAsc()));
        PageInfo info = new PageInfo(withdrawChannelConfDao.selectAll());
        List<WithdrawChannelConfVo> list = BeanConverUtils.convertBeanList(info.getList(), WithdrawChannelConfVo.class);
        return new PageVo<>(info.getTotal(), bo.getPage(), bo.getPageSize(), list);
    }
}
